package com.zs.leymovie.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zs.leymovie.R;
import com.zs.leymovie.bean.CinemaDataEntity;

import java.util.List;

/**
 * Created by Administrator on 2015/8/18.
 */
public class YY_PtrAdapter extends AppAdapter<CinemaDataEntity> {
    public YY_PtrAdapter(List<CinemaDataEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.yy_ptrlist_item, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        CinemaDataEntity entity = list.get(position);
        vh.title.setText(entity.getName());
        vh.addr.setText(entity.getAddress());

        int show = Integer.valueOf(entity.getShow_num());  //得到排片场
        if (show > 0) {
            StringBuilder sb = new StringBuilder("排片");
            sb.append(show).append("场").append("，今日剩余").append(entity.getRemain_num())
                    .append("场").append(entity.getMax_price()).append("-").append(entity.getMax_price()).append("元");
            vh.summry.setText(sb.toString());
        } else {
            vh.summry.setText("今日该影院没有排场");
        }
        return convertView;
    }

    public static class ViewHolder {
        @ViewInject(R.id.yy_ptrlist_title)
        private TextView title;
        @ViewInject(R.id.yy_ptrlist_addr)
        private TextView addr;
        @ViewInject(R.id.yy_ptrlist_summry)
        private TextView summry;

        public ViewHolder(View itemView) {
            ViewUtils.inject(this, itemView);
        }
    }
}
